from pages.trade_page import TradePage
from tools.driver import open_dingstock
from unittest import TestCase
from pages.recommend_page import RecommendPage
from pages.mine_page import MinePage
import unittest
from time import sleep


class TestComment(TestCase):
    def setUp(self) -> None:
        self.driver = open_dingstock()
        self.recommendpage = RecommendPage(self.driver)
        self.minepage = MinePage(self.driver)
        self.tradepage = TradePage(self.driver)

    def tearDown(self) -> None:
        sleep(1)
        
    def test_a_comment(self):
        """测试交易一级评论"""
        comment_content = '测试交易一级评论'
        self.recommendpage.switch_trade()
        self.tradepage.into_first_trade()
        origin = self.tradepage.get_first_trade_comment_num()
        self.tradepage.comment_first_trade_1(comment_content)
        new = self.tradepage.get_first_trade_comment_num()
        assert int(new)-int(origin) == 1
        
    def test_b_comment_like(self):
        """测试交易一级评论点赞及取消"""
        self.recommendpage.switch_trade()
        self.tradepage.into_first_trade()
        self.tradepage.like_first_trade_comment1()
        sleep(1)
        origin = self.tradepage.is_like_num_exist()
        self.tradepage.like_first_trade_comment1()
        sleep(1)
        new = self.tradepage.is_like_num_exist()
        assert origin == True and new == False
        
    def test_c_comment_delete(self):
        """测试交易一级评论删除"""
        self.recommendpage.switch_trade()
        self.tradepage.into_first_trade()
        origin = self.tradepage.get_first_trade_comment_num()
        self.tradepage.delete_first_trade_comment1()
        new = self.tradepage.get_first_trade_comment_num()
        assert int(origin) - int(new) == 1
        
    def test_d_comment_copy(self):
        """测试交易一级评论复制"""
        self.recommendpage.switch_trade()
        self.tradepage.into_first_trade()
        self.tradepage.copy_comment_content()
        assert self.tradepage.is_text_toast_exist('已复制')
        
    def test_e_comment_report(self):
        """测试交易一级评论举报"""
        self.recommendpage.switch_trade()
        self.tradepage.into_first_trade()
        self.tradepage.report_comment()
        assert self.tradepage.is_text_toast_exist('举报成功')
        
    def test_f_comment_private(self):
        """测试交易私信作者"""
        self.recommendpage.switch_trade()
        self.tradepage.into_first_trade()
        origin = self.tradepage.detail_author_name()
        self.tradepage.click_contact_author()
        new = self.tradepage.contact_autor_name()
        assert origin == new
        

if __name__ == '__main__':
    unittest.main()
        
        
